package com.common.app.utls.network.interceptor

import android.os.Build
import com.common.app.data.bean.KeyPre
import com.common.app.utls.Constants
import com.common.app.utls.TrackUtils.getAnonymousID
import com.common.app.utls.Utils
import com.common.base.app.extras.yes
import com.common.base.utils.AppUtils
import com.common.base.utils.AppUtils.getIMEI
import com.common.base.utils.AppUtils.getIpAddress
import com.common.base.utils.DeviceInfoUtil.getCarrier
import com.common.base.utils.DeviceInfoUtil.getMacAddress
import com.common.base.utils.DeviceInfoUtil.getOaid
import com.common.base.utils.DeviceInfoUtil.getOperatorType
import com.common.base.utils.SpUtilsManagement
import com.common.base.utils.VersionUtils
import com.common.base.utils.ViewUtils
import java.net.URLEncoder
import java.util.concurrent.ConcurrentHashMap

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2024/5/31
 *
 * 描述：网络请求拦截器自定义添加信息
 *
 * 修订历史：
 *
 */
object HeadersInterceptorsConfig {
    private val headers = ConcurrentHashMap<String, String>()

    fun getInterceptorsConFig(): ConcurrentHashMap<String, String> {
        (headers.isEmpty() && SpUtilsManagement.getBoolean(KeyPre.KEY_HAD_SHOWED_PRIVACY_DIALOG, false)).yes {
            val oaid: String = getOaid(AppUtils.getContext())
            if (oaid.isNotEmpty()) {
                headers["OAID"] = oaid
            }
            val aid: String = getAnonymousID()
            if (aid.isNotEmpty()) {
                headers["AAID"] = aid
            }
            headers["ROM"] = Build.ID
            headers["Manufacture"] = Build.MANUFACTURER
            headers["Carrier"] = URLEncoder.encode(getCarrier(AppUtils.getContext()), "UTF-8")
            headers["androidId"] = Constants.deviceId
            headers["mac"] = getMacAddress(AppUtils.getContext())
            headers["model"] = Build.MODEL
            headers["vendor"] = Build.BRAND
            headers["screenWidth"] = ViewUtils.getScreenWidth().toString()
            headers["screenHeight"] = ViewUtils.getScreenHeight().toString()
            headers["operatorType"] = URLEncoder.encode(getOperatorType(AppUtils.getContext()), "UTF-8")
            headers["ipv4"] = getIpAddress() ?: ""
            headers["osVersion"] = Build.VERSION.RELEASE
            headers["version_code"] = VersionUtils.getVerCode(AppUtils.getContext()).toString()
            headers["versionName"] = VersionUtils.getVerName(AppUtils.getContext())
            headers["appPackage"] = AppUtils.getPackageName()
            headers["appName"] = URLEncoder.encode(AppUtils.getAppName(), "UTF-8")
            headers["dip"] = Utils.getDisplayMetrics().density.toString()
        }

        return headers
    }
}